
package com.syed;

import com.syed.R;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.ListView;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
//import android.widget.Adapter;

public class TourCreationAndroid extends Activity {
	Button add;
	EditText name;
	Spinner displayBuildings;
	ListView listAddedBuildings;
	Button reset;
	Button submit;
	String array_spinner[]=new String[4];
	String array_spinner_default[]=new String[4];
	String array_tour[]=new String[4];
    int x=0;
	
	ArrayAdapter <String> listOfBuildingsFromDatabase;
	ArrayAdapter <String> listOfBuildingsInTour;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        //Display Buildings
        displayBuildings = (Spinner) findViewById(R.id.spinner1);
        listAddedBuildings = (ListView)findViewById(R.id.listView1);
        
        array_spinner[0]= "Fookie";
        array_spinner[1]= "FOokie";
        array_spinner[2]= "FoOkie";
        array_spinner[3]= "FooKie";
        array_spinner_default[0]= "Fookie";
        array_spinner_default[1]= "FOokie";
        array_spinner_default[2]= "FoOkie";
        array_spinner_default[3]= "FooKie";
        
        array_tour[0]= " ";
        array_tour[1]= " ";
        array_tour[2]= " ";
        array_tour[3]= " ";
        
        listOfBuildingsInTour = new ArrayAdapter<String>(this , android.R.layout.simple_list_item_1,array_tour);
        listAddedBuildings.setAdapter(listOfBuildingsInTour);
	    
        listOfBuildingsFromDatabase = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, array_spinner);
	    displayBuildings.setAdapter(listOfBuildingsFromDatabase); 
	        
        // Buttons onClickListeners
        add = (Button) findViewById(R.id.button1);

        add.setOnClickListener(new OnClickListener() { 
           //@Override 
           public void onClick(View v) { 
        	   if(x!=4 && !array_spinner[displayBuildings.getSelectedItemPosition()].equals("")){
        		   
        	   array_tour[x]= array_spinner[displayBuildings.getSelectedItemPosition()] ;
        	   array_spinner[displayBuildings.getSelectedItemPosition()] = "";
        	   x++;
        	   }
        	   else{
        		   //Display the list is full
        	   }
        	   displayBuildings.setAdapter(listOfBuildingsFromDatabase); 
        	   listAddedBuildings.setAdapter(listOfBuildingsInTour);
           } 
          }); 
        reset = (Button) findViewById(R.id.button2);

        reset.setOnClickListener(new OnClickListener() { 
           //@Override 
           public void onClick(View v) { 
              //reset was clicked!
               array_tour[0]= " ";
               array_tour[1]= " ";
               array_tour[2]= " ";
               array_tour[3]= " ";
               array_spinner[0]= array_spinner_default[0];
               array_spinner[1]= array_spinner_default[1];
               array_spinner[2]= array_spinner_default[2];
               array_spinner[3]= array_spinner_default[3];
               displayBuildings.setAdapter(listOfBuildingsFromDatabase); 
        	   listAddedBuildings.setAdapter(listOfBuildingsInTour);
        	   x=0;
           } 
          }); 
        submit = (Button) findViewById(R.id.button3);

          submit.setOnClickListener(new OnClickListener() { 
             //@Override 
             public void onClick(View v) { 
                //submit was clicked! 
             } 
            }); 
       
    }
}